import { contextBridge,ipcRenderer} from 'electron'
import { electronAPI } from '@electron-toolkit/preload'


// Custom APIs for renderer
const api = {

  saveFile:(data)=>{
    ipcRenderer.send('saveFile',data)
    
  },
  async getFile () {
    return ipcRenderer.invoke('read-file' )
    // const result = await ipcRenderer.invoke('read-file' )
    // console.log('===========',result);
  }
  
}

// Use `contextBridge` APIs to expose Electron APIs to
// renderer only if context isolation is enabled, otherwise
// just add to the DOM global.
if (process.contextIsolated) {
  try {
    contextBridge.exposeInMainWorld('electron', electronAPI)
    contextBridge.exposeInMainWorld('api', api)
    // contextBridge.exposeInMainWorld('myApi', {
    //   saveFile:(data)=>{
    //     ipcRenderer.send('saveFile',data)
    //   }
    // })
  } catch (error) {
    console.error(error)
  }
} else {
  // @ts-ignore (define in dts)
  window.electron = electronAPI
  // @ts-ignore (define in dts)
  window.api = api
}
